package org.hqs.nurse.controller;

import org.hqs.nurse.common.JsonResult;
import org.hqs.nurse.pojo.Nurse;
import org.hqs.nurse.service.NurseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nurse")
public class NurseController {

    @Autowired
    private NurseService nurseService;

    @Autowired
    public NurseController(NurseService nurseService) {
        this.nurseService = nurseService;
    }

    @GetMapping
    public JsonResult<List<Nurse>> getAllNurses() {
        return new JsonResult<>(nurseService.getAllNurses());
    }

    @GetMapping("/{id}")
    public JsonResult<Nurse> getNurseById(@PathVariable Long id) {
        return new JsonResult(nurseService.getNurseById(id));
    }

    @PostMapping
    public JsonResult saveNurse(@RequestBody Nurse nurse) {
        nurseService.saveNurse(nurse);
        return new JsonResult("200", "新增成功");
    }

    @PutMapping("/{id}")
    public JsonResult updateNurse(@PathVariable Long id, @RequestBody Nurse nurse) {
        nurse.setId(id);
        nurseService.updateNurse(nurse);
        return new JsonResult("200", "更新成功");
    }

    @DeleteMapping("/{id}")
    public JsonResult deleteNurse(@PathVariable Long id) {
        nurseService.deleteNurse(id);
        return new JsonResult("200", "删除成功");
    }
}
